﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.CacheManager;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;

public partial class UserCourseListDest_courselistDestbrowser : AdminUserBase
{
    CourselistDestModule CDM = new CourselistDestModule();
    V_adminUser currentAdminUser;
    public string courselisthtml;
    public string courselistDesthtml;

    string trainid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        currentAdminUser = (V_adminUser)Session["currentAdminUser"];

       
        showTrainClassList();

        if (IsPostBack == false)
        {
           // searchshow();
            bindPageData();
           
        }
    }
    #region 删除数据

    /// <summary>
    /// 删除方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbdelete_Command(object sender, CommandEventArgs e)
    {
        V_courselistDest V_CLD = new V_courselistDest();
        V_CLD.SchoolID = currentAdminUser.SchoolID;
        string[] ab = e.CommandArgument.ToString().Split(',');
        V_CLD.TrainClassId = int.Parse(ab[0]);
        V_CLD.UserID = int.Parse(ab[1]);
       // V_CLD.UserID = 1;
        CDM.DeleCourselistDest(V_CLD);
        Response.Redirect("courselistDestbrowser.aspx");

    }
    #endregion

    #region 读取所有培训班名称
    /// <summary>
    /// 读取所有培训班名称
    /// </summary>
    private void showTrainClassList()
    {
        if (Request.QueryString["trainClassId"] != "")
        {
            trainid = Request.QueryString["trainClassId"];
        }
        if (trainid == "")
        {
            courselisthtml = "<span>全部</span>" + "&nbsp;&nbsp;";
        }
        else
        {
            courselisthtml = "<a href=\"?\"><span>全部</span></a>" + "";
        }

        DataSet ds = CDM.CreateCourseDs(currentAdminUser.SchoolID.ToString());
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            courselisthtml += "<a href=\"?trainClassId=" + dr["id"].ToString() + "\"/><span>";
            courselisthtml += dr["vtc_name"].ToString();
            courselisthtml += "</span></a>";
        }
        //courselisthtml += "</div>";

    }
    #endregion
    #region 被注释掉的方法
    /// <summary>
    /// 显示培训班级
    /// </summary>
    //private void showCourselist()
    //{

    //    if (Request.QueryString["trainClass"] != null)
    //    {
    //        trainClass = Request.QueryString["trainClass"].ToString();
    //    }
    //    DataSet ds;
    //    ds = CDM.CreateCourseDs(currentAdminUser.SchoolID.ToString());
    //    if (trainClass == "")
    //    {
    //        courselisthtml = "全部培训班级" + "&nbsp;&nbsp;";
    //    }
    //    else
    //    {
    //        courselisthtml = "<a href=\"?\">全部培训班级</a>" + "&nbsp;&nbsp;";
    //    }

    //    foreach (DataRow dr in ds.Tables[0].Rows)
    //    {

    //        if (trainClass == dr["ID"].ToString())
    //        {
    //            courselisthtml += dr["vtc_name"].ToString() + "&nbsp;&nbsp;";
    //        }
    //        else
    //        {
    //            courselisthtml += "<a href=\"?trainClassID=" + dr["ID"].ToString() + "\" />";
    //            courselisthtml += dr["vtc_name"].ToString();
    //            courselisthtml += "</a>" + "&nbsp;&nbsp;";
    //        }

    //    }
    //}


    // /// <summary>
   ///// 显示搜索结果
   ///// </summary>
   // private void searchshow()
   // {

   //     //删除
   //     if (Request.QueryString["vtc_name"] != null)
   //     {
   //         V_courselistDest V_CLD = new V_courselistDest();
   //         V_CLD.TrainClassid = int.Parse(Request.QueryString["vtc_name"].ToString().Split('|')[0]);
   //         V_CLD.UserID = int.Parse(Request.QueryString["vu_realname"].ToString().Split('|')[1]);
   //         V_CLD.SchoolID = currentAdminUser.SchoolID;

   //         CDM.DeleCourselistDest(V_CLD);
   //     }

   //     //显示搜索结果

   //     string VU_loginname = tb_VU_loginname.Text.ToString();
   //     string VU_realname = tb_VU_realname.Text.ToString();
   //     DataSet ds;
   //     int id = this.CurrentUser.SchoolID;
   //     ds = CDM.QuaryBySchoolIdAll(id);
   //     courselistDesthtml = "<table class='tal'>";
   //     courselistDesthtml += "<tr>";
   //     courselistDesthtml += "<th class='ta3 ta2'>操作</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>学校名称</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>培训班名称</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>人员名称</th>";
   //     courselistDesthtml += "</tr>";
   //     #region
   //     ds = CDM.searchCourselistDest(
   //             currentAdminUser.SchoolID.ToString(), courseID,
   //             VU_loginname, VU_realname);

   //     courselistDesthtml = "<table class='ta1'>";
   //     courselistDesthtml += "<tr>";
   //     courselistDesthtml += "<th  class='ta3 ta2'>操作</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>管理员姓名</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>学员姓名</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>登录名</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>课程名称</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>授课日期</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>教室</th>";
   //     courselistDesthtml += "<th class='ta3 ta2'>授课教师</th>";
   //     courselistDesthtml += "</tr>";

   //     foreach (DataRow dr in ds.Tables[0].Rows)
   //     {
   //         courselistDesthtml += "<tr>";
   //         courselistDesthtml += "<td class='inp1'><a href='?courseID=" + courseID + "&deleid=" + dr["courselistID"].ToString() + "|" + dr["UserID"].ToString() + "'>删除</a></td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["VU_realname"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["VU_loginname"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["VU_loginname"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["VC_name"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + DateTime.Parse(dr["VCL_startDate"].ToString()).ToString("yyyy-MM-dd") + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["VR_roomName"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["VT_realname"].ToString() + "</td>";
   //         courselistDesthtml += "</tr>";

   //     }
   //     #endregion
   //     foreach (DataRow dr in ds.Tables[0].Rows)
   //     {


   //         courselistDesthtml += "<tr>";
   //         courselistDesthtml += "<td class='inp1'><a href='?trainClass=" + trainClass + "&deleid=" + dr["vtc_name"].ToString() + "'>删除</a></td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["vs_name"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["vtc_name"].ToString() + "</td>";
   //         courselistDesthtml += "<td class='ta2'>" + dr["vu_realname"].ToString() + "</td>";
   //         courselistDesthtml += "</tr>";
   //     }


   //     courselistDesthtml += "</table>";
   // }
    #endregion
    #region 分页功能
    /// <summary>
    ///  分页
    /// </summary>
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        bindPageData();
    }
    
    public void bindPageData()
    {
        int schoolid = this.CurrentUser.SchoolID;
        string sqlWhere = " and vu_realname like '%" + this.tb_VU_realname.Text.Trim() + "%'  and vu_loginname like '%" + this.tb_VU_loginname.Text.Trim() + "%'";
        DataSet ds;
        if (!string.IsNullOrEmpty(trainid))
        {
            ds = CDM.QueryCourselistDest(schoolid, int.Parse(trainid), sqlWhere);
        }
        else
        {
            ds = CDM.QueryBySchoolIdAll(schoolid, trainid); 
        }
        repDesc.DataSource = this.getPage(ds);
        repDesc.DataBind();
    }

    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
    #endregion

    #region 根据真实姓名或者登录名查找学员
    /// <summary>
    /// 根据真实姓名或者登录名查找学员
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        int schoolid = this.CurrentUser.SchoolID;
        string vu_logionname = this.tb_VU_loginname.Text.Trim().ToString();
        string vu_realname = this.tb_VU_realname.Text.Trim().ToString();

        string sqlWhere = " and vu_realname like '%" + this.tb_VU_realname.Text.Trim() + "%'  and vu_loginname like '%" + this.tb_VU_loginname.Text.Trim() + "%'";
        DataSet ds = new DataSet();
        if (string.IsNullOrEmpty(this.trainid))
        {
            ds = CDM.QueryCourselistDest(schoolid, sqlWhere);
        }
        else
            ds = CDM.QueryCourselistDest(schoolid, int.Parse(this.trainid), sqlWhere);
        repDesc.DataSource = this.getPage(ds); ;
        repDesc.DataBind();
    }

    #endregion
    ////修改
    //public void btnUpdate_Click(object sender, CommandEventArgs e)
    //{
    //    Response.Redirect("UpdateCourseList.aspx?id=" + e.CommandArgument.ToString());
    //}
    
}
